package cn.wolfcode.wms.service.impl;

import cn.wolfcode.wms.domain.Depot;
import cn.wolfcode.wms.mapper.DepotMapper;
import cn.wolfcode.wms.page.PageResult;
import cn.wolfcode.wms.qo.QueryObject;
import cn.wolfcode.wms.service.IDepotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepotService implements IDepotService {


    @Autowired
    private DepotMapper mapper;

    public int deleteByPrimaryKey(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    public int insert(Depot depot) {
        return mapper.insert(depot);
    }

    public Depot selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<Depot> selectAll() {
        return mapper.selectAll();
    }

    public int updateByPrimaryKey(Depot depot) {
        return mapper.updateByPrimaryKey(depot);
    }


    public void saveorupdate(Depot depot) {

        System.out.println(depot);
        if (depot.getId() != null) {
            mapper.updateByPrimaryKey(depot);
        } else {
            mapper.insert(depot);
        }
    }

    public void delete(Long id) {
        if(id != null){
            mapper.deleteByPrimaryKey(id);
        }


    }

    public PageResult query(QueryObject qo) {
       int count = mapper.queryForCount(qo);
       if(count == 0){
           return  PageResult.empty(qo.getPageSize());
       }
       List<Depot> list = mapper.queryForList(qo);

        PageResult pageResult = new PageResult(qo.getPageSize(), count, qo.getCurrentPage(), list);


        return pageResult;
    }
}

